home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / netbsd / contrib / apsfilter < prev    next >
Text File  |  1994-06-09  |  34KB  |  1,122 lines

  1. #!/bin/sh
  2.  
  3. ################################################################################
  4. # Only for debugging purposes. You can find debugging output in
  5. # the logfile (see /etc/printcap definition lf=/var/spool/.../log)
  6. ################################################################################
  7. #
  8. set -x
  9. export PKFONTS=/usr/TeX/lib/tex/fonts/pk
  10. export TEXPOOL=/usr/TeX/lib/tex
  11. export MFPOOL=/usr/TeX/lib/mf
  12. export TEXINPUTS=/usr/TeX/lib/tex/inputs
  13. export MFBASES=/usr/TeX/lib/mf/bases
  14. export TEXFONTS=/usr/TeX/lib/tex/fonts/tfm
  15. # ______________________________________________________________________________
  16. #
  17. # apsfilter-1.11 ------ TEXT / PS / DVI input filter  -----------
  18. #                       ============================
  19. #
  20. #        for Unix Systems with BSD alike print mechanism (lpd, printcap)
  21. #
  22. #        by Andreas Klemm <andreas@knobel.knirsch.de>
  23. #
  24. # Sun Mar 20 11:46:43 GMT+0100 1994
  25. # ______________________________________________________________________________
  26. #
  27. #
  28. # Features:    - Enables non-Postscript printers to print PS files
  29. # --------    - automatically recognizes filetypes
  30. #          (currently supported ascii / data / postscript / TeX DVI)
  31. #          using the Unix command file(1) ( -> /etc/magic)
  32. #        - uses gs and dvips as filter to process PS && DVI files
  33. #        - initializes some printer to fine default values 
  34. #        - if a print fault occurs when using dvips or gs:
  35. #            -> ejects loaded paper automatically
  36. #            -> root will be notified via e-mail (NOTIFY variable)
  37. #            -> the tmp file is left in $TMP_DIR
  38. #        - resets printer after a printjob
  39. #        - resolution and papersize
  40. #          are selected automatically for gs and dvips.
  41. #        - allows printing of ascii text with ``german umlauts''
  42. #          and "raw" Postscript files without calling gs
  43. #          if apsfilter is called under the name "aps-forceascii" 
  44. #        - uses lpr's command line arguments -wwidth -iindent -llength
  45. #        - uses pr for printing ascii texts (as an option you
  46. #          can disable the ps header)
  47. #
  48. # Installation:
  49. # ------------    - HP Deskjet Family and Canon BJ   -> plug and play ;-)
  50. #        - other printer supported by gs       -> configure and play ;->
  51. #
  52. #        Normally **only two** steps are necessary
  53. #        =========================================
  54. #
  55. #        - modify the PRINTER shell variable in this script
  56. #          (see my comments which types/names are supported)
  57. #
  58. #        - modify /etc/printcap: 
  59. #            set ``if'' (path to input filter) variable
  60. #            :if=_Complete_Pathname_to_apsfilter_:
  61. #            (see example in this file)
  62. #
  63. #_______________________________________________________________________________
  64. #
  65. # Andreas Klemm                 /\/\____ Wiechers & Partner Datentechnik GmbH 
  66. # andreas@knobel.knirsch.de ___/\/\/     andreas@wupmon.wup.de (Unix Support)
  67. #_______________________________________________________________________________
  68. #
  69.  
  70. ################################################################################
  71. #
  72. # Changes 1.10 -> 1.11
  73. #
  74. ################################################################################
  75. #
  76. # A last minute hack caused file type autorecognition to fail :-(
  77. # The culprit: I only appended $PATH to the search path for machine 
  78. # specific search paths. And boom :-(
  79. # After removing $PATH from the PATH= line everything works perfectly now.
  80. # Oh folks .. the next time I don't include wishes from people without 
  81. # testing, even if the changes are soooo minimal as in this case '-)
  82. #
  83. # No line in this script exceeds 80 columns any more,
  84. # as suggested by Stephen Hsieh <sch2@crux5.cit.cornell.edu>
  85. #
  86. # Modified the way how apsfilters command line arguments are stored
  87. # in environment variables, 
  88. # as suggested by Dirk Sturzebecher <dirk@flop.escape.de>
  89. #
  90.  
  91. ################################################################################
  92. #
  93. # Changes 1.9 -> 1.10
  94. #
  95. ################################################################################
  96. #
  97. # introduced shell functions print_ps, print_dvi, print_ascii, ....
  98. # is needed for the new program functions to force printing of ascii, which
  99. # is needed for printing "deutsche Umlaute"
  100. #
  101. # problems with "deutschen Umlauten"
  102. # Text containing "Deutsche Umlaute" may be interpreted as data, so cr/nl 
  103. # conversion for deskjet and possibly other printer doesn't work.
  104. # A possible solution is to force the script to handle imput data as text or
  105. # something else.
  106. #
  107. # exit 1 on print fault caused lpd to print the file again and again
  108. # and lots of tmp files made TMP_DIR full.. so we have to exit 0 in any case
  109. #
  110. # Introduced MAILX variable. /bin/mail = elm on Linux. Elm didn't find
  111. # ~/Mail directory, so it failed to send $NOTIFY a mail when a print error
  112. # occurred.
  113. #
  114. # David Frey <dfrey@stud.ee.ethz.ch>:
  115. # use lpr's command line arguments -wwidth -iindent -llength, pipe ascii
  116. # through pr
  117. #
  118. # and some more ...
  119. #
  120.  
  121. ################################################################################
  122. #
  123. # Changes 1.8 -> 1.9
  124. #
  125. ################################################################################
  126. #
  127. # Thu Feb 24 18:45:00 GMT+0100 1994
  128. #
  129. # removed compression option that was introduced with 1.8
  130. # since dvips can't read from a pipe...
  131. #
  132. # canon bj printer don't have a common command set ...
  133. # So the bj* commands I introduced were only valid for the bj200.
  134. #
  135.  
  136. ################################################################################
  137. #
  138. # Changes 1.7 -> 1.8
  139. #
  140. ################################################################################
  141. #
  142. # Sun Feb 20 14:02:29 GMT+0100 1994
  143. #
  144. # Optionally (default=yes) compresses temporary files used by this script
  145. # See COMPRESS option. On slow systems wit low memory you may want to disable
  146. # this feature. (Suggestions from Bill - physics.purdue.edu!bcr)
  147. #
  148. # Rewrote parts of my comments and shortened the script by simly referencing
  149. # the GNU GPL.
  150. #
  151.  
  152.  
  153. ################################################################################
  154. #
  155. # Changes 1.6 -> 1.7
  156. #
  157. ################################################################################
  158. #
  159. # Wed Feb 16 21:57:57 GMT+0100 1994
  160. #
  161. #    - Support for Canon Bubblejets (Bill - physics.purdue.edu!bcr)
  162. #    - fixed nec resolution from 300 to 360 dpi in dvips part
  163. #
  164.  
  165.  
  166. ################################################################################
  167. #
  168. # Changes 1.5 -> 1.6
  169. #
  170. ################################################################################
  171. #
  172. # Sat Feb  5 13:10:33 GMT+0100 1994 (AKL)
  173. #
  174. #    rearranged this script to be an input filter
  175. #    use if=/usr/local/bin/apsfilter in /etc/printcap
  176. #    advantage: you can mix the file types in on command line
  177. #            lpr postscript_file ascii_file ....
  178. #        
  179. # ------------------------------------------------------------------------------
  180. #
  181. # Sat Feb  5 13:29:24 GMT+0100 1994 (AKL)
  182. #        
  183. #    removed quit.ps, because it caused trouble for some people.
  184. #
  185. # ------------------------------------------------------------------------------
  186. #
  187. # Sat Feb  5 13:39:18 GMT+0100 1994 (AKL)
  188. #
  189. #    dvips: added useful command line options (see: section 10)
  190. #
  191. #    - run dvips in quiet mode
  192. #    - print last page first for some printers
  193. #    - compress bitmap fonts when resolution is greater or equal 400 dpi
  194. #    - trying to set printer resolution for dvips && gs correctly
  195. #
  196. #    suggestion from: sar@beehive.mn.org (Steven A. Reisman)
  197. #    set paper type for dvips && gs correctly
  198. #
  199. # ------------------------------------------------------------------------------
  200. #
  201. # Sat Feb  5 16:17:31 GMT+0100 1994 (AKL)
  202. #
  203. #    from: sch2@crux5.cit.cornell.edu (Stephen Hsieh)
  204. #          - cr/nl conversion needed for laserjets when printing ascii
  205. #
  206. ################################################################################
  207.  
  208. ################################################################################
  209. #
  210. # *** INSTALLATION ****
  211. #
  212. #        a) modify your file: /etc/printcap
  213. #
  214. #        b) and install apsfilter with proper permissions
  215. #
  216. #         c) modify the PRINTER environment variable in this script
  217. #           config section (2)
  218. #
  219. #        d) optional: change other parameters in config section (3) ff.
  220. #
  221. ################################################################################
  222. #
  223. # Example:    HP Deskjet connected to a PC's parallel Centronix interface
  224. #        (Linux Slackware 1.1.1)
  225. #
  226. # lp|deskjet|HP Deskjet 500:\
  227. #    :lp=/dev/lp1:\                <== printer device
  228. #    :sd=/var/spool/lp1:\            <== spool directory
  229. #    :lf=/usr/spool/lp1/log:\        <== logfile
  230. #    :af=/usr/spool/lp1/acct:\        <== accounting file
  231. #    :if=/usr/local/bin/apsfilter:\        <== full path to apsfilter
  232. #    :mx#0:\                    <== no size restriction
  233. #    :sh:                    <== suppress banner page !
  234. #
  235. #
  236. # And a 2nd entry to have the possibility to force the script to treat binary
  237. # data to be printed as ascii text (since german texts with umlauts are often
  238. # recognized as data files...)
  239. #
  240. # lp|deskjet|HP Deskjet 500:\
  241. #    :lp=/dev/lp1:\                <== printer device
  242. #    :sd=/var/spool/lp1:\            <== spool directory
  243. #    :lf=/usr/spool/lp1/log:\        <== logfile
  244. #    :af=/usr/spool/lp1/acct:\        <== accounting file
  245. #    :if=/usr/local/bin/aps-forceascii:\    <== ascii_only filter
  246. #                            symlink to apsfilter
  247. #    :mx#0:\                    <== no size restrictions
  248. #    :sh:                    <== suppress banner page !
  249. #
  250. #     copy apsfilter to /usr/local/bin/apsfilter and make it executable
  251. #    and make a symbolic link to aps-forceascii
  252. #
  253. #        mkdir /usr/local/bin || mkdir -p /usr/local/bin
  254. #        cp apsfilter /usr/local/bin
  255. #        ln -s /usr/local/bin/apsfilter /usr/local/bin/aps-forceascii
  256. #        chmod 555 /usr/local/bin/apsfilter
  257. #        chown lp /usr/local/bin/apsfilter
  258. #        chgrp lp /usr/local/bin/apsfilter
  259. #
  260. # double check the permissions of spool directory....
  261. #
  262. # I) For the printer itself (sd=/var/spool/lp1):
  263. #
  264. #    drwxrwx---   2 root     lp           1024 Feb  5 16:53 /var/spool/lp1
  265. #
  266. #        shell commands to do this (as root):
  267. #            mkdir /var/spool/lp1
  268. #            chown root.lp /var/spool/lp1
  269. #            chmod 770 /var/spool/lp1
  270. #
  271. # II) For the line printer daemon lpd:
  272. #
  273. #     Permissions of lpd (on Linux Slackware 1.1.1):
  274. #
  275. #        -r-x------   1 root  lp    39696 Aug 12 17:44 /usr/sbin/lpd
  276. #
  277. #     Needed Permissions for lpd spool dir:
  278. #
  279. #        drwxrwx---   2 root  lp     1024 Dec 31 15:59 /var/spool/lpd
  280. #
  281. #        shell commands to do this (as root):
  282. #            mkdir /var/spool/lpd
  283. #            chown root.lp /var/spool/lpd
  284. #            chmod 770 /var/spool/lpd
  285. #
  286. # III) Check your /etc/magic, see file(1) magic(5)
  287. #      maybe you have to add some lines for Postscript and dvi recognition
  288. #
  289. #      # magic.postscript: Magic for postscript files
  290. #      0    string        %!        PostScript document
  291. #      >2    string    PS-Adobe-        conforming
  292. #      >11    string    1.0            at level %s
  293. #      >11    string    2.0            at level %s
  294. #      # magic.tex: 
  295. #      0    short    0173402    DVI File
  296. #      >16    string    >\0    (%s)
  297. #      0    short    0173531    Packed TeX Font
  298. #      >4    string    >\0    (%s)
  299. #      2    string    \000\022    Metafont Font Metric
  300. #      >34    string    >\0    (%s)
  301. #
  302.  
  303. ################################################################################
  304. #
  305. # D e b u g g i n g
  306. # - - - - - - - - -
  307. #
  308. # Activate the debug switch at the beginning of the script (set -x).
  309. # Then you can find debugging output in the printers logfile.
  310. # Don't forget to comment out the debug switch later otherwise
  311. # your logfile will grow very quickly ;-)
  312. #
  313. ################################################################################
  314.  
  315. ################################################################################
  316. #
  317. # Supported printers by Ghostscript - important for printing ps files
  318. #
  319. #    [ pick one name and modify the PRINTER variable below ]
  320. #
  321. ################################################################################
  322. #
  323. # Version dependend -- Ghostscript 2.6.1 PL 4 supports:
  324. #
  325. # *    appledmp  Apple Dot Matrix Printer (should also work with Imagewriter)
  326. #    bj10e      Canon BubbleJet BJ10e
  327. # *    bj200      Canon BubbleJet BJ200
  328. # *    cdeskjet  H-P DeskJet 500C with 1 bit/pixel color
  329. # *    cdjcolor  H-P DeskJet 500C with 24 bit/pixel color and
  330. #              high-quality color (Floyd-Steinberg) dithering
  331. # *    cdjmono   H-P DeskJet 500C printing black only
  332. # *    cdj500      H-P DeskJet 500C (same as cdjcolor)
  333. # *    cdj550      H-P DeskJet 550C
  334. # *    declj250  alternate DEC LJ250 driver
  335. # +    deskjet   H-P DeskJet and DeskJet Plus
  336. # *    dfaxhigh  DigiBoard, Inc.'s DigiFAX software format (high resolution)
  337. # *    dfaxlow   DigiFAX low (normal) resolution
  338. #    djet500   H-P DeskJet 500
  339. # *    djet500c  H-P DeskJet 500C
  340. #    epson      Epson-compatible dot matrix printers (9- or 24-pin)
  341. # +    eps9high  Epson-compatible 9-pin, interleaved lines
  342. #               (triple resolution)
  343. # *    epsonc      Epson LQ-2550 and Fujitsu 3400/2400/1200 color printers
  344. # *    escp2      Epson ESC/P 2 language printers, including Stylus 800
  345. # +     ibmpro    IBM 9-pin Proprinter
  346. # *    jetp3852  IBM Jetprinter ink-jet color printer (Model #3852)
  347. # +    laserjet  H-P LaserJet
  348. # *    la50      DEC LA50 printer
  349. # *    la75      DEC LA75 printer
  350. # *    lbp8      Canon LBP-8II laser printer
  351. # *    ln03      DEC LN03 printer
  352. # *    lj250      DEC LJ250 Companion color printer
  353. # +    ljet2p      H-P LaserJet IId/IIp/III* with TIFF compression
  354. # +    ljet3      H-P LaserJet III* with Delta Row compression
  355. # +    ljet4      H-P LaserJet 4 (defaults to 600 dpi)
  356. # +    ljetplus  H-P LaserJet Plus
  357. # *    m8510      C.Itoh M8510 printer
  358. # *    necp6      NEC P6/P6+/P60 printers at 360 x 360 DPI resolution
  359. # *    nwp533    Sony Microsystems NWP533 laser printer   [Sony only]
  360. # *    oki182      Okidata MicroLine 182
  361. #    paintjet  H-P PaintJet color printer
  362. # *    pj      alternate PaintJet XL driver 
  363. # *    pjxl      H-P PaintJet XL color printer
  364. # *    pjxl300   H-P PaintJet XL300 color printer
  365. # *    r4081      Ricoh 4081 laser printer
  366. # *    sparc      SPARCprinter
  367. # *    t4693d2   Tektronix 4693d color printer, 2 bits per R/G/B component
  368. # *    t4693d4   Tektronix 4693d color printer, 4 bits per R/G/B component
  369. # *    t4693d8   Tektronix 4693d color printer, 8 bits per R/G/B component
  370. # *    tek4696   Tektronix 4695/4696 inkjet plotter
  371. #
  372.  
  373. ################################################################################
  374. #
  375. # ENVIRONMENT SECTION - Global setting
  376. #
  377. ################################################################################
  378. #
  379. # Reference of Shell Variables:
  380. # -----------------------------
  381. #
  382. #    (1)  PATH        <- Command search path
  383. #                   should fit everybodies needs
  384. #     (2)  PRINTER        <- Type of Printer
  385. #                   - set it manually or by install script
  386. #                   - is *BASE* for other environment variables
  387. #    (3)  TMP_DIR        <- directory for temporary files
  388. #                   (/var/tmp should be ok for everybody)
  389. #    (4)  NOTIFY        <- who gets mail when printer fault occurrs
  390. #                   root is a sane default
  391. #    (5)  MAILX        <- Your mailx program (can -s "Subject" option)
  392. #     (6)  GS_RESOL        <- printer resolution, used for gs(1)
  393. #                   computed automatically for some printers
  394. #                   depends on PRINTER variable
  395. #    (7)  PAPERSIZE        <- correct papersize for gs
  396. #                   computed automatically for some printers
  397. #                   depends on PRINTER variable
  398. #    (8)  DVIPS_OPTS        <- options for dvips
  399. #                   some options are defaults some are computed
  400. #                   automatically. Depends on the following
  401. #                   variables:
  402. #                    PRINTER, GS_RESOL, PAPERSIZE
  403. #    (9)  WANT_PS_HEADER    <- Do you want a pr(1) header in ascii output ?
  404. #    (10) ECHO        <- the echo command, that does control character
  405. #                   expansion
  406. #
  407. ################################################################################
  408.  
  409. #-------------------------------------------------------------------------------
  410. #
  411. # (1)  PATH - SET SEARCH PATH
  412. #    
  413. #-------------------------------------------------------------------------------
  414.  
  415. # PATH=......:$PATH
  416. # Note !       ^------- This goes wrong, don't know why, perhaps a Linux
  417. #            release specific problem
  418. #
  419. PATH=/usr/bin:/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/TeX/bin:/local/bin:/usr/bin/X11:/usr/ghostscript/bin
  420.  
  421. #-------------------------------------------------------------------------------
  422. #
  423. # (2)  PRINTER - SET PRINTER TYPE
  424. #    
  425. #-------------------------------------------------------------------------------
  426.  
  427. PRINTER=laserjet
  428.  
  429. #-------------------------------------------------------------------------------
  430. #
  431. # (3)  TMP_DIR - SET LOCATION FOR TEMPORARY FILES
  432. #
  433. #-------------------------------------------------------------------------------
  434.  
  435. case `uname -s` in
  436.     Linux|linux)        TMP_DIR=/var/tmp    ;;
  437.     Solaris|solaris)    TMP_DIR=/var/tmp    ;;
  438.     Sun*|sun*)        TMP_DIR=/var/tmp    ;;
  439.     *)            TMP_DIR=/tmp        ;;
  440. esac
  441.  
  442. #-------------------------------------------------------------------------------
  443. #
  444. # (4)  NOTIFY - SET E-MAIL ADRESS OF PRINTER ADMINISTRATOR
  445. #-------------------------------------------------------------------------------
  446.  
  447. NOTIFY=root
  448.  
  449. #-------------------------------------------------------------------------------
  450. #
  451. # (5)  MAILX - your favourite mail program that understands "-s" (except elm !)
  452. #      
  453. #    typical Linux problems: /bin/mail is often a symlink to elm which
  454. #    doesn't work since it misses the Mail folder directory, etc ....
  455. #    Use the mailx program instead. Another advantage of mailx is, that
  456. #    you can give a Subject with -s on the command line.
  457. #    SunOS 4.1.X, Solaris 1 note: I think there is a program "Mail" which does
  458. #    the job.
  459. #
  460. #-------------------------------------------------------------------------------
  461.  
  462. # note: hope it's correct ... otherwise 1.11, puh ;-)
  463.  
  464. case `uname -s` in
  465.     Linux|linux)        MAILX=mailx    ;;
  466.     Solaris|solaris)    MAILX=Mail    ;;
  467.     Sun*|sun*)        MAILX=Mail    ;;
  468.     *)            MAILX=mailx    ;;
  469. esac
  470.  
  471.  
  472. #-------------------------------------------------------------------------------
  473. #
  474. # (6) PRINTER RESOLUTION - GS_RESOL
  475. #
  476. #        if you have other Printers than HP's with 300x300 pixel or 
  477. #        nec's with 360x360 then you have to add something reasonable 
  478. #        for your printer !!!
  479. #
  480. #-------------------------------------------------------------------------------
  481.  
  482. case $PRINTER in
  483.     cdesk*|cdj*|desk*|djet*)
  484.                 GS_RESOL=300x300
  485.                 ;;
  486.     laserjet|ljet*)
  487.                 GS_RESOL=300x300
  488.                 ;;
  489.     paintjet|pj*)
  490.                 GS_RESOL=300x300
  491.                 ;;
  492.     necp6|bj200)
  493.                 GS_RESOL=360x360
  494.                 ;;
  495.     *)
  496.                 #
  497.                 # when printer is not known exactly
  498.                 # we assume a default of 300x300
  499.                 #
  500.                 GS_RESOL=300x300
  501.                 ;;
  502. esac
  503.  
  504. #-------------------------------------------------------------------------------
  505. #
  506. # (7) PAPERSIZE - FOR GS (GHOSTSCRIPT)
  507. #
  508. #    Letter note legal
  509. #    a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10
  510. #    b0 b1 b2 b3 b4 b5
  511. #    archE archD archC archB archA
  512. #    flsa flse
  513. #    halfletter
  514. #    11x17
  515. #    ledger
  516. #
  517. #-------------------------------------------------------------------------------
  518.  
  519. PAPERSIZE=a4
  520.  
  521.  
  522. #-------------------------------------------------------------------------------
  523. #
  524. # (8) OPTIONS for dvips - DVIPS_OPTS
  525. #
  526. #        -q quiet mode
  527. #        -r print last page first
  528. #        -t papertype
  529. #            (look known formats in the config file config.ps
  530. #             on Linux Slackware usually in /usr/TeX/lib/tex/ps)
  531. #        -D num horizontal + vertical resolution in dpi 
  532. #           or:    -X num horizontal resolution in dpi 
  533. #            -Y num vertical   resolution in dpi 
  534. #        -Z compress bitmap fonts
  535. #           usually only when resolution is >= 400
  536. #
  537. #-------------------------------------------------------------------------------
  538.  
  539. case $PRINTER in
  540.     cdesk*|cdj*|desk*|djet*)
  541.                 DVIPS_OPTS="-q -D 300 -r -Z"
  542.                 ;;
  543.     laserjet|ljet*)
  544.                 DVIPS_OPTS="-q -D 300"
  545.                 ;;
  546.     paintjet|pj*)
  547.                 DVIPS_OPTS="-q -D 300"
  548.                 ;;
  549.     necp6|bj200)
  550.                 DVIPS_OPTS="-q -D 360 -r"
  551.                 ;;
  552.     *)
  553.                 #
  554.                 # when printer is not known exactly
  555.                 # we assume a default of 300x300
  556.                 #
  557.                 DVIPS_OPTS="-q -D 300 -r"
  558.                 ;;
  559. esac
  560.  
  561. case $GS_RESOL in
  562.     360x360|400x400|600x600)        
  563.                 #
  564.                 # compress bitmap fonts if you have a 
  565.                 # high resolution printer
  566.                 #
  567.                 DVIPS_OPTS="$DVIPS_OPTS -Z"
  568.                 ;;
  569. esac
  570.  
  571. case $PAPERSIZE in
  572.  
  573.     letter|legal|ledger)    DVIPS_OPTS="$DVIPS_OPTS -t $PAPERSIZE"
  574.                 ;;
  575.     a3)            DVIPS_OPTS="$DVIPS_OPTS -t A3"
  576.                 ;;
  577.     a4)            DVIPS_OPTS="$DVIPS_OPTS -t A4"
  578.                 ;;
  579.     *)            DVIPS_OPTS="$DVIPS_OPTS -t letter"
  580.                 ;;
  581. esac
  582.  
  583.  
  584. #-------------------------------------------------------------------------------
  585. #
  586. # (9) WANT_PR_HEADER - do you want a pr header when printing ascii ?
  587. #
  588. #-------------------------------------------------------------------------------
  589.  
  590. #WANT_PR_HEADER=Yes
  591. WANT_PR_HEADER=No
  592.  
  593. #-------------------------------------------------------------------------------
  594. #
  595. # (10) Your echo command that handels control characters in strings
  596. #
  597. #-------------------------------------------------------------------------------
  598.  
  599. # Linux - bash
  600. ECHO="printf "
  601.  
  602. # Rest of the world...?
  603. #ECHO=echo
  604.  
  605.  
  606. ################################################################################
  607. ################################################################################
  608. ################################################################################
  609. ####
  610. #### C O P Y R I G H T 
  611. ####
  612. ################################################################################
  613. ################################################################################
  614. ################################################################################
  615. #
  616. #
  617. # You are permitted to use this script in the terms of the 
  618. #
  619. #             GNU GENERAL PUBLIC LICENSE
  620. #                Version 2, June 1991
  621. #
  622. #  Copyright (C) 1989, 1991 Free Software Foundation, Inc.
  623. #                           675 Mass Ave, Cambridge, MA 02139, USA
  624. #  Everyone is permitted to copy and distribute verbatim copies
  625. #  of this license document, but changing it is not allowed.
  626.  
  627.  
  628. ################################################################################
  629. ################################################################################
  630. ################################################################################
  631. ####
  632. #### POSSIBLE MODIFICATIONS / additional contributors
  633. ####
  634. ####        suggestions from other creative people
  635. ####        which use another configuration than I
  636. ####
  637. ################################################################################
  638. ################################################################################
  639. ################################################################################
  640. #
  641. # DO YOU WANT HEADER PAGES ?!?!
  642. #
  643. #            Jeff Stern <jstern@eclectic.ss.uci.edu>
  644. #            Mon Nov  1 21:21:45 GMT 1993
  645. #
  646. # "... I changed to using it as an input filter instead of an output 
  647. #  filter. This way I can still print header pages without confusing 
  648. #  the filter. This necessarily required adding a command to tell 
  649. #  printcap to send a formfeed at the beginning of opening the device 
  650. #  and also specifying that that formfeed really also includes the 
  651. #  LF-> CR+LF translation: this is so that the translation also will 
  652. #  work for the header page, too."
  653. #
  654. #  Necessary printcap entry instead of the default for HP Deskjet's:
  655. #
  656. #    lp:lp=/dev/lp1:sd=/var/spool/lp1:if=/usr/local/bin/apsfilter:mx#0:\
  657. #       :lf=/usr/adm/lpd-errs:ff=\033E\033&k2G\033&a10L:fo
  658. #
  659.  
  660.  
  661. ################################################################################
  662. ################################################################################
  663. ################################################################################
  664. #####
  665. ##### S h e l l  -  F u n c t i o n s
  666. #####
  667. ################################################################################
  668. ################################################################################
  669. ################################################################################
  670.  
  671.  
  672. ################################################################################
  673. #
  674. # eject() - EJECT PAGE COMMAND
  675. #
  676. #            - if an error condition occurrs when gs is working
  677. #              then the possibly partial printed page isn't 
  678. #              ejected automatically. So we have to do it !
  679. #
  680. ################################################################################
  681.  
  682. eject() {
  683.  
  684.     case $PRINTER in
  685.  
  686.         cdesk*|cdj*|desk*|djet*)
  687.                     # send pcl command for page eject
  688.                     $ECHO "\033&l0H\c"
  689.                     ;;
  690.         laserjet|ljet*)
  691.                     # send pcl command for page eject
  692.                     # hope that's correct for them, too ;->
  693.                     $ECHO "\033&l0H\110"
  694.                     ;;
  695.         paintjet|pj*)
  696.                     # send pcl command for page eject
  697.                     # hope that's correct for them, too ;->
  698.                     $ECHO "\033&l0H\c"
  699.                     ;;
  700.                 bj200)
  701.                                         # page eject
  702.                                         $ECHO "\0334\c"
  703.                                         ;;
  704.     esac
  705.  
  706.     #------------------------------------------------------------
  707.     # If an error occurrs, then preserve tmp file
  708.     #------------------------------------------------------------
  709.  
  710.     Preserve=1
  711. }
  712.  
  713.  
  714. ################################################################################
  715. #
  716. # FUNCTION reset() - RESET PRINTER
  717. #
  718. #        (shell function - printer dependend)
  719. #
  720. ################################################################################
  721.  
  722. reset() {
  723.  
  724.     case $PRINTER in
  725.  
  726.         cdesk*|cdj*|desk*|djet*)
  727.                     # send pcl command for Printer Reset
  728.                     $ECHO "\033E\c"
  729.                     ;;
  730.         laserjet|ljet*)
  731.                     # send pcl command for Printer Reset
  732.                     # should be correct for them, too ;->
  733.                     $ECHO "\033E"
  734.                     ;;
  735.         paintjet|pj*)
  736.                     # send pcl command for Printer Reset
  737.                     # should be correct for them, too ;->
  738.                     $ECHO "\033E\c"
  739.                     ;;
  740.                 bj200)
  741.                                         # send pcl command for Printer Reset
  742.                                         $ECHO "\033E\c"
  743.                                         ;;
  744.     esac
  745. }
  746.  
  747.  
  748. ################################################################################
  749. #####################  N E W   W I T H   1.10  #################################
  750. ################################################################################
  751. ####
  752. ####           The shell functions for printing ps, dvi, ....
  753. ####
  754. ################################################################################
  755. ################################################################################
  756. ################################################################################
  757.  
  758.  
  759. #===============================================================================
  760. #
  761. # pipe ps data through ghostscript
  762. #
  763. #===============================================================================
  764.  
  765. print_ps()
  766. {
  767.     cat $TMP_FILE            \
  768.     | gs                \
  769.         -q            \
  770.         -sDEVICE=${PRINTER}    \
  771.         -r${GS_RESOL}        \
  772.         -sPAPERSIZE=${PAPERSIZE}\
  773.         -dNOPAUSE        \
  774.         -dSAFER            \
  775.         -sOutputFile=-        \
  776.         -            \
  777.     || eject
  778.     #    ^  if an error occurs, then
  779.     #    eject already loaded paper
  780.     #    calls printer dependend function
  781. }
  782.  
  783.  
  784. #===============================================================================
  785. #
  786. # print dvi data using dvips->gs
  787. #
  788. #===============================================================================
  789.  
  790. print_dvi()
  791. {
  792.     dvips -f $DVIPS_OPTS        \
  793.     < $TMP_FILE            \
  794.     | gs                \
  795.         -q            \
  796.         -sDEVICE=${PRINTER}    \
  797.         -r${GS_RESOL}        \
  798.         -sPAPERSIZE=${PAPERSIZE}\
  799.         -dNOPAUSE        \
  800.         -dSAFER            \
  801.         -sOutputFile=-        \
  802.         -            \
  803.     || eject
  804.     #    ^  if an error occurs, then
  805.     #    eject already loaded paper
  806.     #    calls printer dependend function
  807.  
  808. }    # EOF print_dvi()
  809.  
  810.  
  811. #===============================================================================
  812. #
  813. # print ascii and fine tune printer settings ...
  814. #
  815. #===============================================================================
  816.  
  817. print_ascii()
  818. {
  819.  
  820.     #------------------------------------------------------------
  821.     # print ascii - BEGIN of Printer Dependend Part
  822.     #------------------------------------------------------------
  823.  
  824.     case $PRINTER in 
  825.  
  826.         cdesk*|cdj*|desk*|djet*)
  827.  
  828.             #------------------------------------
  829.             # Something special for Deskjets ...
  830.             #------------------------------------
  831.             #
  832.             # print normal text with
  833.             #    - cr/nl conversion
  834.             #    - letter quality
  835.             #    - 66 lines/page
  836.             #    - left margin
  837.             #    - 12 cpi pitch
  838.         
  839.             # LINE TERMINATION    \E & k # G
  840.             #    0 = CR=CR   ; LF=LF   ; FF=FF (default)
  841.             #    1 = CR=CR+LF; LF=LF   ; FF=FF
  842.             # **    2 = CR=CR   ; LF=CR+LF; FF=CR+FF
  843.             #    3 = CR=CR+LF; LF=CR+LF; FF=CR+FF
  844.             $ECHO "\033&k2G"
  845.  
  846.             # QUALITY        \E ( s # Q
  847.             #       1 = draft    = 240cps
  848.             # **    2 = letter    = 120cps (default)
  849.             $ECHO "\033(s1Q"
  850.  
  851.             # Text Scale Mode        \E & k # W
  852.             #       5 = off (default)
  853.             #         6 = on
  854.             #    ignored in landscape mode
  855.             $ECHO "\033&k5W"
  856.  
  857.             # Perforation Skip Mode        \E & l # L
  858.             #       0 = off = 0.0 in Top Margin
  859.             #       1 = on  = 1/2 in Top Margin (default)
  860.             $ECHO "\033&l0L"
  861.  
  862.             ## pr does the job now !
  863.             ## Left Margin            \E & a # L
  864.             ##     # Value = column number
  865.             ##    default = 0 = 1/8 in left margin
  866.             ##    used = 7 for 1" left margin
  867.             ## $ECHO "\033&a7L"
  868.  
  869.             # Pitch                \E ( s # H
  870.             #    # = cpi
  871.             #    default = 10 characters per inch
  872.             # **    12 cpi
  873.             $ECHO "\033(s12H"
  874.             ;;
  875.  
  876.         laserjet|ljet*)
  877.             #------------------------------------
  878.             # Something special for Laserjets ...
  879.             #------------------------------------
  880.             #
  881.             # print normal text with
  882.             #    - cr/nl conversion
  883.  
  884.             # LINE TERMINATION    \E & k # G
  885.             #    0 = CR=CR   ; LF=LF   ; FF=FF (default)
  886.             #    1 = CR=CR+LF; LF=LF   ; FF=FF
  887.             # **    2 = CR=CR   ; LF=CR+LF; FF=CR+FF
  888.             #    3 = CR=CR+LF; LF=CR+LF; FF=CR+FF
  889.             $ECHO "\033&k2G"
  890.             ;;
  891.  
  892.         bj200)
  893.             # LINE TERMINATION      \E #
  894.             #       0 = CR=CR   ; LF=LF
  895.             # **    1 = CR=CR   ; LF=CR+LF
  896.             $ECHO "\033\000\000"
  897.  
  898.             # QUALITY               \E %
  899.             #       G = double strike
  900.             # **    H = single strike
  901.             $ECHO "\033H\000"
  902.  
  903.             # Set proportional printing     \E #
  904.             # **    0 = off (default)
  905.             #       1 = on
  906.             $ECHO "\033\000\000"
  907.  
  908.             # Perferation Skip Mode         \E % (#)
  909.             #       N (#) =  # lines
  910.             #       O = off
  911.             $ECHO "\033O\000"
  912.  
  913.             ## pr does the job now !!!
  914.             ## Horizontal Margin             \E X # #
  915.             ##       # # == left and right (units?)
  916.             ## $ECHO "\033X\010\127\000"
  917.  
  918.             # Pitch                         \E :
  919.             # **    12 cpi                  \E :
  920.             #       default = 10 characters per inch
  921.             $ECHO "\033:\000"
  922.             ;;
  923.  
  924.         *)    #
  925.             # Any other printer: do nothing, sorry ;-)
  926.             # Please give me a note what to include
  927.             # here for your special printer folks ...
  928.             #
  929.             ;;
  930.     esac
  931.     #EOF Printer Dependend Part
  932.  
  933.     #
  934.     # And now print ascii tmp file
  935.     #
  936.  
  937.     if [ "$WANT_PR_HEADER" = "Yes" ]
  938.     then
  939.         pr -r -w $WIDTH -l $LENGTH -o $INDENT -h $LOGINNAME@$HOST \
  940. #        pr -r -f -w $WIDTH -l $LENGTH -o $INDENT -h $LOGINNAME@$HOST \
  941.         $TMP_FILE
  942.     else
  943.         pr -t -r -w $WIDTH -l $LENGTH -o $INDENT $TMP_FILE
  944.     fi
  945.     
  946.  
  947. }    #EOF print_ascii()
  948.  
  949.  
  950. #===============================================================================
  951. #
  952. # print data files and fine tune printer settings ...
  953. #
  954. #===============================================================================
  955.  
  956. print_data()
  957. {
  958.  
  959.     #------------------------------------------------------------
  960.     # print DATA - BEGIN of Printer Dependend Part
  961.     #------------------------------------------------------------
  962.  
  963.     case $PRINTER in 
  964.  
  965.         cdesk*|cdj*|desk*|djet*|laserjet|ljet*)
  966.  
  967.             # LINE TERMINATION    \E & k # G
  968.             # **    0 = CR=CR   ; LF=LF   ; FF=FF (default)
  969.             #    1 = CR=CR+LF; LF=LF   ; FF=FF
  970.             #       2 = CR=CR   ; LF=CR+LF; FF=CR+FF
  971.             #    3 = CR=CR+LF; LF=CR+LF; FF=CR+FF
  972.             $ECHO "\033&k0G"
  973.             ;;
  974.  
  975.         bj200)
  976.                  # LINE TERMINATION      \E #
  977.             #       0 = CR=CR   ; LF=LF
  978.             # **    1 = CR=CR   ; LF=CR+LF
  979.             $ECHO "\0331\000\c"
  980.             ;;
  981.  
  982.         *)
  983.             ;;
  984.     esac
  985.     #------------------------------------------------------------
  986.     # print DATA - END of Printer Dependend Part
  987.     #------------------------------------------------------------
  988.  
  989.     #------------------------------------------------------------
  990.     # And now print DATA tmp file
  991.     #------------------------------------------------------------
  992.  
  993.     cat $TMP_FILE
  994.  
  995. }    #EOF print_data()
  996.  
  997.  
  998. #===============================================================================
  999. #
  1000. # UNKNOWN file type, too bad ;->
  1001. #
  1002. #===============================================================================
  1003.  
  1004. fault_filetype()
  1005. {
  1006.     # make noise on system console
  1007.     echo "apsfilter: unknown filetype $FILE_TYPE" > /dev/console
  1008.  
  1009.     # mail to printer admin
  1010.     echo "apsfilter: $TMP_FILE: unknown filetype $FILE_TYPE" \
  1011.     | $MAILX -s "apsfilter: printer fault" $NOTIFY \
  1012.     2> /dev/null
  1013.  
  1014.     # don't remove print file
  1015.     Preserve=Yes
  1016.  
  1017. }    #EOF fault_filetype()
  1018.     
  1019.  
  1020. #  / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
  1021. # / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
  1022. #  / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
  1023. #
  1024. #   M A I N  ( )
  1025. #
  1026. #  / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
  1027. # / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
  1028. #  / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
  1029.  
  1030.  
  1031. #\
  1032. # >    Temp. filename
  1033. #/
  1034.  
  1035. TMP_FILE=$TMP_DIR/apsfilter.$$
  1036.  
  1037. #\
  1038. # >    write print data from stdin to temp file
  1039. #/
  1040.  
  1041. cat - > $TMP_FILE
  1042.  
  1043. #\
  1044. # >    reset printer (shell function - printer dependend)
  1045. #/
  1046.  
  1047. reset
  1048.  
  1049. #\    evaluate command line arguments that are given to the
  1050. # \    input filter 
  1051. #  \  
  1052. #   >    apsfilter [-c] -wwidth -llength -iindent -n login -h host acct-file     
  1053. #  /              $1      $2       $3    $4   $5  $6  $7     $8
  1054. # /    defaults: width=0, length=66, indent=0
  1055. #/
  1056.  
  1057. WIDTH=`echo $1 | awk '{ print substr($1,3) }'`
  1058. if [ ! $WIDTH ]; then WIDTH=80; fi
  1059. LENGTH=`echo $2 | awk '{ print substr($1,3) }'`
  1060. if [ ! $LENGTH ]; then LENGTH=66; fi
  1061. INDENT=`echo $3 | awk '{ print 1+substr($1,3) }'`
  1062. if [ ! $INDENT ]; then INDENT=0; fi
  1063. LOGINNAME=$5
  1064. HOST=$7
  1065.  
  1066.  
  1067. #\
  1068. # \    if apsfilter is called/used under the name "aps-forceascii", then
  1069. #  >    the script skips "filetype autorecognition" 
  1070. # /    necessary to print files with "deutschen Umlauten" ;-)
  1071. #/
  1072.  
  1073. BASENAME=`basename $0`
  1074.  
  1075. case $BASENAME in
  1076.     *ascii*) 
  1077.         print_ascii ;;
  1078.  
  1079.     *)
  1080.  
  1081.     #\
  1082.     # \    **** FILE TYPE AUTO_RECOGNITION *****
  1083.     #  \    
  1084.     #   \    first set output of the ``file'' command to new script arguments
  1085.     #    >    $1, $2, ..., $n
  1086.     #   /
  1087.     #  /    then throw away $1 since that is the *file name*
  1088.     # /    the rest is a "string" which consist of one or multiple words 
  1089.     #/    describing the file type. For example: "Korn Shell Script"
  1090.  
  1091.     set -- `file $TMP_FILE`
  1092.     shift ; FILE_TYPE=$*
  1093.  
  1094.     case $FILE_TYPE in
  1095.         PostScript*)            print_ps    ;;
  1096.         *DVI*)                print_dvi    ;;
  1097.         *ascii*|*text*|*script*)    print_ascii    ;;
  1098.         *data*)                print_data    ;;
  1099.         *)                fault_filetype    ;;
  1100.     esac
  1101. esac
  1102.  
  1103. #\
  1104. # \    Preserve tmp File in $TMP_DIR for later examination
  1105. #  >    if error conndition occurred.
  1106. # /    Perhaps you have to modify /etc/magic ... who knows ...
  1107. #/
  1108.  
  1109. if [ "$Preserve" = "Yes" ]
  1110. then 
  1111.     # don't remove tmp file
  1112.     exit 0
  1113. else
  1114.     # reset printer (shell function - printer dependend)
  1115.     rm -f $TMP_FILE
  1116.     reset
  1117.     exit 0
  1118. fi
  1119.